import { getActivityFilterRequest } from '@/types/activity'

export const formattingSqlIN = (array: Array<number>) => {
  let formattingString: string = ''
  if (array.length === 0) {
    return ''
  }
  array.forEach((item) => {
    formattingString += `${item},`
  })
  return formattingString.slice(0, -1)
}

export const formattingQueryActivityFilter = (request: getActivityFilterRequest): string => {
  let queryString: string = ''
  //依次判断request属性不为空
  const { activityCompleteTime, activityDetailAddress, activityName, activityStartTime, activityTypes, organizerName } = request
  if (activityName) {
    queryString += `ActivityName=${activityName}`
  }
  if (activityTypes) {
    if (queryString.length === 0) {
      queryString += `ActivityType=${activityTypes}`
    } else {
      queryString += `&ActivityType=${activityTypes}`
    }
  }
  if (activityCompleteTime) {
    if (queryString.length === 0) {
      queryString += `ActivityEndTime=${activityCompleteTime}`
    } else {
      queryString += `&ActivityEndTime=${activityCompleteTime}`
    }
  }
  if (activityStartTime) {
    if (queryString.length === 0) {
      queryString += `ActivityStartTime=${activityStartTime}`
    } else {
      queryString += `&ActivityStartTime=${activityStartTime}`
    }
  }
  if (organizerName) {
    if (queryString.length === 0) {
      queryString += `OrganizerName=${organizerName}`
    } else {
      queryString += `&OrganizerName=${organizerName}`
    }
  }
  if (activityDetailAddress) {
    if (queryString.length === 0) {
      queryString += `ActivityBriefAddress=${activityDetailAddress}`
    } else {
      queryString += `&ActivityBriefAddress=${activityDetailAddress}`
    }
  }
  return queryString
}
